Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo build intermittently fails on darwin platform #10022

Closed
akscram opened this issue Oct 31, 2021 · 20 comments
Closed

cargo build intermittently fails on darwin platform #10022

akscram opened this issue Oct 31, 2021 · 20 comments
Labels
C-bug Category: bug O-macos OS: macOS S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.

Comments

@akscram
Copy link

akscram commented Oct 31, 2021

Problem

cargo build intermittently fails for a project or its dependencies and subsequent re-builds succeed. For example, bitfield doesn't have dependencies but this problem is observed for the project itself:

ash@cube ~/git/rust-bitfield % cargo build
   Compiling bitfield v0.13.2 (/Users/ash/git/rust-bitfield)
error: could not compile `bitfield`

Caused by:
  process didn't exit successfully: `rustc --crate-name bitfield src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C metadata=c7b624d34760ee7b -C extra-filename=-c7b624d34760ee7b --out-dir /Users/ash/git/rust-bitfield/target/debug/deps -C incremental=/Users/ash/git/rust-bitfield/target/debug/incremental -L dependency=/Users/ash/git/rust-bitfield/target/debug/deps` (signal: 6, SIGABRT: process abort signal)
ash@cube ~/git/rust-bitfield % cargo build
   Compiling bitfield v0.13.2 (/Users/ash/git/rust-bitfield)
    Finished dev [unoptimized + debuginfo] target(s) in 0.18s

Subsequent rebuilds sometimes don't help and some project continue failing.

Steps

  1. Try to build a cargo project

Possible Solution(s)

No response

Notes

This problem is observed on:

macOs Monterey
Version 12.0.1

Version

cargo 1.55.0
release: 1.55.0
@akscram akscram added the C-bug Category: bug label Oct 31, 2021
@akscram akscram changed the title cargo build intermittently fails on darwin platform cargo build intermittently fails on darwin platform Oct 31, 2021
@georgik
Copy link

georgik commented Nov 3, 2021

The same problem with SIGABRT simulated on Monterey x86_64.
The same build works without SIGABRT on Big Sur x86_64, Catalina x86_64 and Monterey aarch64.

@YorikSar
Copy link

YorikSar commented Nov 3, 2021

It looks like this issue is not reproduced on latest cargo & rustc versions. If I run cargo from nixpkgs, I see this error:

 % nix run nixpkgs#cargo build
   Compiling bitfield v0.13.2 (/Users/yorik/tmp/rust-bitfield)
error: could not compile `bitfield`

Caused by:
  process didn't exit successfully: `rustc --crate-name bitfield src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C metadata=c7b624d34760ee7b -C extra-filename=-c7b624d34760ee7b --out-dir /Users/yorik/tmp/rust-bitfield/target/debug/deps -C incremental=/Users/yorik/tmp/rust-bitfield/target/debug/incremental -L dependency=/Users/yorik/tmp/rust-bitfield/target/debug/deps` (signal: 6, SIGABRT: process abort signal)

Nixpkgs have Rust 1.55:

 % nix run nixpkgs#cargo -- --version                                      
cargo 1.55.0

But if I install toolchains with rustup and use them, everything's ok:

 % nix run nixpkgs#rustup -- install stable
...
 % nix run nixpkgs#rustup -- install nightly
...
 % PATH=~/.rustup/toolchains/nightly-x86_64-apple-darwin/bin:$PATH cargo build
   Compiling bitfield v0.13.2 (/Users/yorik/tmp/rust-bitfield)
    Finished dev [unoptimized + debuginfo] target(s) in 0.30s
 % PATH=~/.rustup/toolchains/stable-x86_64-apple-darwin/bin:$PATH cargo build
   Compiling bitfield v0.13.2 (/Users/yorik/tmp/rust-bitfield)
    Finished dev [unoptimized + debuginfo] target(s) in 0.35s

(stable is 1.56.0, nightly is 1.58.0-nightly)

But also if I install 1.55.0 with rustup, I don't get this error:

 % nix run nixpkgs#rustup -- install 1.55
 ...
 % PATH=~/.rustup/toolchains/1.55-x86_64-apple-darwin/bin:$PATH cargo build
   Compiling bitfield v0.13.2 (/Users/yorik/tmp/rust-bitfield)
    Finished dev [unoptimized + debuginfo] target(s) in 0.38s

@afh
Copy link

afh commented Nov 4, 2021

Could this be related to a change in default user limits (file descriptors) from macOS 11 to macOS 12?

% sw_vers
ProductName:    macOS
ProductVersion: 11.6.1
BuildVersion:   20G224
% ulimit -n
4864
% sw_vers
ProductName:    macOS
ProductVersion: 12.0.1
BuildVersion:   21A559
% ulimit -n
256

Changing the file descriptor limit on macOS 12 to the default value of macOS 11 (ulimit -n 4864) allows me to build alacritty using nixpkgs.

@YorikSar
Copy link

YorikSar commented Nov 4, 2021

I can confirm, raising fd limit helps on my system as well:

 % ulimit -n
256
 % nix run nixpkgs#cargo -- build
   Compiling bitfield v0.13.2 (/Users/yorik/tmp/rust-bitfield)
error: could not compile `bitfield`

Caused by:
  process didn't exit successfully: `rustc --crate-name bitfield src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C metadata=c7b624d34760ee7b -C extra-filename=-c7b624d34760ee7b --out-dir /Users/yorik/tmp/rust-bitfield/target/debug/deps -C incremental=/Users/yorik/tmp/rust-bitfield/target/debug/incremental -L dependency=/Users/yorik/tmp/rust-bitfield/target/debug/deps` (signal: 6, SIGABRT: process abort signal)
 % ulimit -n 4096                
 % ulimit -n     
4096
 % nix run nixpkgs#cargo -- build
   Compiling bitfield v0.13.2 (/Users/yorik/tmp/rust-bitfield)
    Finished dev [unoptimized + debuginfo] target(s) in 0.56s

@akscram
Copy link
Author

akscram commented Nov 4, 2021

I've tried it but rustc still intermittently fails with the same error:

ash@cube ~/git/rust-bitfield % ulimit -n
256
ash@cube ~/git/rust-bitfield % ulimit -n 4096
ash@cube ~/git/rust-bitfield % ulimit -n
4096
ash@cube ~/git/rust-bitfield % rustc --crate-name bitfield src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C metadata=c7b624d34760ee7b -C extra-filename=-c7b624d34760ee7b --out-dir /Users/ash/git/rust-bitfield/target/debug/deps -C incremental=/Users/ash/git/rust-bitfield/target/debug/incremental -L dependency=/Users/ash/git/rust-bitfield/target/debug/deps
ash@cube ~/git/rust-bitfield % rustc --crate-name bitfield src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C metadata=c7b624d34760ee7b -C extra-filename=-c7b624d34760ee7b --out-dir /Users/ash/git/rust-bitfield/target/debug/deps -C incremental=/Users/ash/git/rust-bitfield/target/debug/incremental -L dependency=/Users/ash/git/rust-bitfield/target/debug/deps
ash@cube ~/git/rust-bitfield % rustc --crate-name bitfield src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C metadata=c7b624d34760ee7b -C extra-filename=-c7b624d34760ee7b --out-dir /Users/ash/git/rust-bitfield/target/debug/deps -C incremental=/Users/ash/git/rust-bitfield/target/debug/incremental -L dependency=/Users/ash/git/rust-bitfield/target/debug/deps
ash@cube ~/git/rust-bitfield % rustc --crate-name bitfield src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C metadata=c7b624d34760ee7b -C extra-filename=-c7b624d34760ee7b --out-dir /Users/ash/git/rust-bitfield/target/debug/deps -C incremental=/Users/ash/git/rust-bitfield/target/debug/incremental -L dependency=/Users/ash/git/rust-bitfield/target/debug/deps
rustc(97469,0x70000dc95000) malloc: *** error for object 0x60000247f500: pointer being realloc'd was not allocated
rustc(97469,0x70000dc95000) malloc: *** set a breakpoint in malloc_error_break to debug
zsh: abort      rustc --crate-name bitfield src/lib.rs --error-format=json  --crate-type lib

Execution under cargo still fails too:

ash@cube ~/git/rust-bitfield % cargo clean
ash@cube ~/git/rust-bitfield % cargo build
   Compiling bitfield v0.13.2 (/Users/ash/git/rust-bitfield)
error: could not compile `bitfield`

Caused by:
  process didn't exit successfully: `rustc --crate-name bitfield src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C metadata=c7b624d34760ee7b -C extra-filename=-c7b624d34760ee7b --out-dir /Users/ash/git/rust-bitfield/target/debug/deps -C incremental=/Users/ash/git/rust-bitfield/target/debug/incremental -L dependency=/Users/ash/git/rust-bitfield/target/debug/deps` (signal: 6, SIGABRT: process abort signal)

@afh
Copy link

afh commented Nov 4, 2021

Thanks for chiming in @akscram, I see you set the fd limit to 4096, just as @YorikSar did, yet that differs from the macOS 11 default of 4864 (at least on my machine), would you mind retrying with that?

@akscram
Copy link
Author

akscram commented Nov 4, 2021

@afh, sure. I tried to set 4864 as you suggested. However, no luck so far, the problem still intermittently reproduces by running cargo:

ash@cube ~/git/rust-bitfield % ulimit -n
4864
ash@cube ~/git/rust-bitfield % cargo clean
ash@cube ~/git/rust-bitfield % cargo build
   Compiling bitfield v0.13.2 (/Users/ash/git/rust-bitfield)
error: could not compile `bitfield`

Caused by:
  process didn't exit successfully: `rustc --crate-name bitfield src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C metadata=c7b624d34760ee7b -C extra-filename=-c7b624d34760ee7b --out-dir /Users/ash/git/rust-bitfield/target/debug/deps -C incremental=/Users/ash/git/rust-bitfield/target/debug/incremental -L dependency=/Users/ash/git/rust-bitfield/target/debug/deps` (signal: 6, SIGABRT: process abort signal)
ash@cube ~/git/rust-bitfield % cargo build
   Compiling bitfield v0.13.2 (/Users/ash/git/rust-bitfield)
error: could not compile `bitfield`

Caused by:
  process didn't exit successfully: `rustc --crate-name bitfield src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C metadata=c7b624d34760ee7b -C extra-filename=-c7b624d34760ee7b --out-dir /Users/ash/git/rust-bitfield/target/debug/deps -C incremental=/Users/ash/git/rust-bitfield/target/debug/incremental -L dependency=/Users/ash/git/rust-bitfield/target/debug/deps` (signal: 6, SIGABRT: process abort signal)
ash@cube ~/git/rust-bitfield % cargo build
   Compiling bitfield v0.13.2 (/Users/ash/git/rust-bitfield)
error: could not compile `bitfield`

Caused by:
  process didn't exit successfully: `rustc --crate-name bitfield src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C metadata=c7b624d34760ee7b -C extra-filename=-c7b624d34760ee7b --out-dir /Users/ash/git/rust-bitfield/target/debug/deps -C incremental=/Users/ash/git/rust-bitfield/target/debug/incremental -L dependency=/Users/ash/git/rust-bitfield/target/debug/deps` (signal: 6, SIGABRT: process abort signal)
ash@cube ~/git/rust-bitfield % cargo build
   Compiling bitfield v0.13.2 (/Users/ash/git/rust-bitfield)
    Finished dev [unoptimized + debuginfo] target(s) in 0.18s

And by running the same rustc command alone:

ash@cube ~/git/rust-bitfield % ulimit -n
4864
ash@cube ~/git/rust-bitfield % rustc --crate-name bitfield src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C metadata=c7b624d34760ee7b -C extra-filename=-c7b624d34760ee7b --out-dir /Users/ash/git/rust-bitfield/target/debug/deps -C incremental=/Users/ash/git/rust-bitfield/target/debug/incremental -L dependency=/Users/ash/git/rust-bitfield/target/debug/deps
ash@cube ~/git/rust-bitfield % rustc --crate-name bitfield src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C metadata=c7b624d34760ee7b -C extra-filename=-c7b624d34760ee7b --out-dir /Users/ash/git/rust-bitfield/target/debug/deps -C incremental=/Users/ash/git/rust-bitfield/target/debug/incremental -L dependency=/Users/ash/git/rust-bitfield/target/debug/deps
rustc(97667,0x7000088bc000) malloc: *** error for object 0x600000194d00: pointer being realloc'd was not allocated
rustc(97667,0x7000088bc000) malloc: *** set a breakpoint in malloc_error_break to debug
zsh: abort      rustc --crate-name bitfield src/lib.rs --error-format=json  --crate-type lib
ash@cube ~/git/rust-bitfield % rustc --crate-name bitfield src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C metadata=c7b624d34760ee7b -C extra-filename=-c7b624d34760ee7b --out-dir /Users/ash/git/rust-bitfield/target/debug/deps -C incremental=/Users/ash/git/rust-bitfield/target/debug/incremental -L dependency=/Users/ash/git/rust-bitfield/target/debug/deps
ash@cube ~/git/rust-bitfield % rustc --crate-name bitfield src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C metadata=c7b624d34760ee7b -C extra-filename=-c7b624d34760ee7b --out-dir /Users/ash/git/rust-bitfield/target/debug/deps -C incremental=/Users/ash/git/rust-bitfield/target/debug/incremental -L dependency=/Users/ash/git/rust-bitfield/target/debug/deps
ash@cube ~/git/rust-bitfield % rustc --crate-name bitfield src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C metadata=c7b624d34760ee7b -C extra-filename=-c7b624d34760ee7b --out-dir /Users/ash/git/rust-bitfield/target/debug/deps -C incremental=/Users/ash/git/rust-bitfield/target/debug/incremental -L dependency=/Users/ash/git/rust-bitfield/target/debug/deps
rustc(97676,0x700009b40000) malloc: *** error for object 0x6000021dcf00: pointer being realloc'd was not allocated
rustc(97676,0x700009b40000) malloc: *** set a breakpoint in malloc_error_break to debug
zsh: abort      rustc --crate-name bitfield src/lib.rs --error-format=json  --crate-type lib

@ehuss ehuss added the S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. label Nov 6, 2021
@lilyball
Copy link
Contributor

lilyball commented Nov 8, 2021

FWIW macOS 12.0.1 on my M1 machine reports a ulimit of 4864, and on my x86-64 machine of 2560. In both cases this appears to be a limit inherited from Terminal.app, as the system default for processes spawned by launchd is 256. I’m pretty sure this was true for macOS 11 as well, I don’t think the system default has changed, just potentially whatever ulimit your terminal emulator is using.

@YorikSar
Copy link

YorikSar commented Nov 8, 2021

@lilyball Thanks for the information. I use Terminal.app also. It looks like bare Terminal.app has ulimit -n of 6400 for me, but in tmux I'm getting 256. That's kind of weird...

That said, shouldn't nix builds be isolated from such configs on the caller side?

@lilyball
Copy link
Contributor

lilyball commented Nov 8, 2021

Looks like nix-daemon on both of my systems is setting the ulimit to 4096.

nix-build -E 'with import <nixpkgs> {}; runCommandNoCC "foo" {} "ulimit -n"'
this derivation will be built:
  /nix/store/a71y1s1g82pgwpamzh9fd1vc30h7hfx0-foo.drv
building '/nix/store/a71y1s1g82pgwpamzh9fd1vc30h7hfx0-foo.drv'...
4096

@afh
Copy link

afh commented Nov 12, 2021

Possibly the SIGABRT is unrelated to user limits then. What could other causes for SIGABRT be? 🤔

@georgik
Copy link

georgik commented Dec 3, 2021

The problem is that Rust/Cargo was compiled without option --set rust.jemalloc for macOS x86_64
To fix the problem add the option to the build script like here https://github.com/rust-lang/rust/blob/acbe4443cc4c9695c0b74a7b64b60333c990a400/src/ci/github-actions/ci.yml#L456

@lilyball
Copy link
Contributor

lilyball commented Dec 3, 2021

@georgik Why would that cause random SIGABRTs though?

@igrr
Copy link

igrr commented Dec 4, 2021

@lilyball Unfortunately the root cause is not clear yet, we have just observed that switching to jemalloc in our builds of rustc (to match the setting used by official rust-lang releases) resolves the issue.

I have tried a few things to debug this.

Here's the backtrace when rustc crashes:

(from lldb -- path/to/broken/rustc /tmp/rust-bitfield/src/lib.rs)
* thread #2, name = 'rustc', stop reason = signal SIGABRT
  * frame #0: 0x00007ff81995d112 libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x00007ff819993233 libsystem_pthread.dylib`pthread_kill + 263
    frame #2: 0x00007ff8198dfd10 libsystem_c.dylib`abort + 123
    frame #3: 0x00007ff8197bd3e2 libsystem_malloc.dylib`malloc_vreport + 548
    frame #4: 0x00007ff8197c05ed libsystem_malloc.dylib`malloc_report + 151
    frame #5: 0x00007ff8197b1542 libsystem_malloc.dylib`realloc + 328
    frame #6: 0x000000010b3df6f4 librustc_driver-e74dfddec80dd206.dylib`alloc::raw_vec::finish_grow::h95b47d0479269564 + 52
    frame #7: 0x000000010beaaaad librustc_driver-e74dfddec80dd206.dylib`alloc::raw_vec::RawVec$LT$T$C$A$GT$::reserve::do_reserve_and_handle::h9a25a6cccb7e4cb0 + 125
    frame #8: 0x000000010b35053e librustc_driver-e74dfddec80dd206.dylib`rustc_expand::mbe::quoted::parse::h1bce1dc409525940 + 910
    frame #9: 0x000000010b35033b librustc_driver-e74dfddec80dd206.dylib`rustc_expand::mbe::quoted::parse::h1bce1dc409525940 + 395
    frame #10: 0x000000010b37bc79 librustc_driver-e74dfddec80dd206.dylib`_$LT$core..iter..adapters..map..Map$LT$I$C$F$GT$$u20$as$u20$core..iter..traits..iterator..Iterator$GT$::fold::hbe68035063654888 + 345
    frame #11: 0x000000010b3c7284 librustc_driver-e74dfddec80dd206.dylib`_$LT$alloc..vec..Vec$LT$T$GT$$u20$as$u20$alloc..vec..spec_from_iter..SpecFromIter$LT$T$C$I$GT$$GT$::from_iter::hd1f69a02989e0958 + 308
    frame #12: 0x000000010b415e2b librustc_driver-e74dfddec80dd206.dylib`rustc_expand::mbe::macro_rules::compile_declarative_macro::h3d8cbb242e86d33a + 2811
    frame #13: 0x000000010a16b5f0 librustc_driver-e74dfddec80dd206.dylib`rustc_resolve::macros::_$LT$impl$u20$rustc_resolve..Resolver$GT$::compile_macro::haab5aa40b0dbebe9 + 64
    frame #14: 0x000000010a110914 librustc_driver-e74dfddec80dd206.dylib`rustc_resolve::build_reduced_graph::BuildReducedGraphVisitor::define_macro::h1bee7e7e0d3c7a59 + 324
    frame #15: 0x000000010a1119cd librustc_driver-e74dfddec80dd206.dylib`_$LT$rustc_resolve..build_reduced_graph..BuildReducedGraphVisitor$u20$as$u20$rustc_ast..visit..Visitor$GT$::visit_item::hcc60cc074b0315f0 + 61
    frame #16: 0x000000010a192b8c librustc_driver-e74dfddec80dd206.dylib`rustc_ast::visit::walk_item::h969a8fbef1f2967c + 556
    frame #17: 0x000000010a111a45 librustc_driver-e74dfddec80dd206.dylib`_$LT$rustc_resolve..build_reduced_graph..BuildReducedGraphVisitor$u20$as$u20$rustc_ast..visit..Visitor$GT$::visit_item::hcc60cc074b0315f0 + 181
    frame #18: 0x000000010a11c52c librustc_driver-e74dfddec80dd206.dylib`rustc_expand::expand::AstFragment::visit_with::h37d94dcc669437d7 + 796
    frame #19: 0x000000010a1600ed librustc_driver-e74dfddec80dd206.dylib`rustc_resolve::macros::_$LT$impl$u20$rustc_expand..base..ResolverExpand$u20$for$u20$rustc_resolve..Resolver$GT$::visit_ast_fragment_with_placeholders::hf5558e1d5cf619a1 + 365
    frame #20: 0x000000010b36150d librustc_driver-e74dfddec80dd206.dylib`rustc_expand::expand::MacroExpander::collect_invocations::hf5d8c097cb76f156 + 685
    frame #21: 0x000000010b35d2d0 librustc_driver-e74dfddec80dd206.dylib`rustc_expand::expand::MacroExpander::fully_expand_fragment::h5bd0472e6fc2de35 + 272
    frame #22: 0x000000010b35ca40 librustc_driver-e74dfddec80dd206.dylib`rustc_expand::expand::MacroExpander::expand_crate::haf540552bf2c28f2 + 1904
    frame #23: 0x0000000107a1a813 librustc_driver-e74dfddec80dd206.dylib`rustc_session::utils::_$LT$impl$u20$rustc_session..session..Session$GT$::time::ha5ff477d8601dc5b + 995
    frame #24: 0x0000000107981c2a librustc_driver-e74dfddec80dd206.dylib`rustc_interface::passes::configure_and_expand::hf3cd0883cea046e9 + 506
    frame #25: 0x00000001079880c8 librustc_driver-e74dfddec80dd206.dylib`rustc_interface::queries::Queries::expansion::hadbcdde2b25d4545 + 984
    frame #26: 0x00000001078a8636 librustc_driver-e74dfddec80dd206.dylib`rustc_interface::queries::_$LT$impl$u20$rustc_interface..interface..Compiler$GT$::enter::h943ad3c48264be25 + 1430
    frame #27: 0x000000010787882e librustc_driver-e74dfddec80dd206.dylib`rustc_span::with_source_map::hf30b994c7d983fc0 + 302
    frame #28: 0x00000001078a7697 librustc_driver-e74dfddec80dd206.dylib`scoped_tls::ScopedKey$LT$T$GT$::set::hb95cf04a014583bb + 1063
    frame #29: 0x000000010787e4c5 librustc_driver-e74dfddec80dd206.dylib`std::sys_common::backtrace::__rust_begin_short_backtrace::hc4d6c302c32140f9 + 341
    frame #30: 0x000000010786dcfd librustc_driver-e74dfddec80dd206.dylib`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h9edd1937c76e0e8b + 109
    frame #31: 0x00000001006a8917 libstd-6bfdd74f78460fb4.dylib`std::sys::unix::thread::Thread::new::thread_start::h1bb1b6861c71687e + 39
    frame #32: 0x00007ff819993514 libsystem_pthread.dylib`_pthread_start + 125
    frame #33: 0x00007ff81998f02f libsystem_pthread.dylib`thread_start + 15
(stderr is the same as shown in https://github.com//issues/10022#issuecomment-960554623, except for the pointer value)

Valgrind doesn't run on macOS 12 yet, so I wasn't able to test with it.

I have also tried enabling Guard Malloc (export DYLD_INSERT_LIBRARIES=/usr/lib/libgmalloc.dylib) but unfortunately the issue isn't reproducible when it is enabled.

Using malloc_info in lldb to figure out if the pointer passed to realloc was allocated or not,

(lldb) script import lldb.macosx.heap
(lldb) run
rustc(2594,0x700002fdc000) malloc: *** error for object 0x600003607100: pointer being realloc'd was not allocated
rustc(2594,0x700002fdc000) malloc: *** set a breakpoint in malloc_error_break to debug
...
(lldb) malloc_info 0x600003607100
0x0000600003607100: malloc(   128) -> 0x600003607100

So it looks like the pointer was indeed allocated. Maybe that's a bug in libsystem's heap implementation that it flags this as pointer being realloc'd was not allocated?

I think the issue is not with cargo and not with rustc-as-a-program. It looks like this also affects other programs compiled with rustc for macOS, when the system allocator is used on macOS 12, for example rayon-rs/rayon#901 (comment).

@lilyball
Copy link
Contributor

lilyball commented Dec 6, 2021

@igrr Can you try turning on malloc stack logging? I'm wondering what malloc_history says about this address.

I'm also curious how "authoritative" malloc_info is. I skimmed its implementation and it looks like it's asking malloc for its zones and iterating them with zone->introspect->enumerator, which certainly seems pretty reliable as it appears that iteration actually iterates every pointer in the zone. However this does not appear to be the same code path realloc uses. I would hope the zone introspection API would agree with everything else, but I just don't know if e.g. malloc_info showing an allocated block actually proves whether the pointer is actually valid.

@ehuss
Copy link
Contributor

ehuss commented Dec 7, 2021

@akscram and everyone else here, can you say how you installed rust? Was it via the official builds (rustup or manually)? Or was it through a package manager?

@igrr
Copy link

igrr commented Dec 7, 2021

@lilyball unfortunately the issue stops being reproducible when malloc stack logging (export MallocStackLogging=1) is enabled. (In my environment, at least.)

@ehuss In my and @georgik 's case these were unofficial builds of rustc done in our fork with Xtensa architecture support. The build scripts we use are in this repository.

Official builds work correctly in the same environment.

Edit: one extra detail, the build which exhibits this issue was performed on macOS 10.15.

@ehuss
Copy link
Contributor

ehuss commented Dec 21, 2021

I have opened rust-lang/rust#92173 on the rustc side for this issue, as the realloc failure is almost certainly not a cargo issue.

I'm still curious about the discussion above about the descriptor limits. That seems unrelated, but I'd like to better understand if it is something that needs attention.

@lilyball
Copy link
Contributor

@ehuss My impression is the file descriptor limits thing was a red herring. I don't believe the default limits changed with the macOS update.

@ehuss
Copy link
Contributor

ehuss commented Dec 23, 2021

Ah, thanks for the update.

I'm going to close this in favor of rust-lang/rust#92173.
Just a reminder that if you are not using an official Rust build to make sure it is built with jemalloc enabled, which seems to work around this issue.

@ehuss ehuss closed this as completed Dec 23, 2021
Minoru added a commit to newsboat/newsboat that referenced this issue Mar 5, 2022
I had to disable Clippy on macOS because it fails with SIGABRT on
Monterey. I found an ostensible workaround[1], but it didn't work for
me. Since we're already running Clippy in many other CI jobs, it
shouldn't matter much that we don't run it on macOS.

1. rust-lang/cargo#10022 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug O-macos OS: macOS S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.
Projects
None yet
Development

No branches or pull requests

7 participants